package edu.nf.placeorder.common.exception;

import edu.nf.placeorder.common.result.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wangl
 * @date 2025/9/28
 */
@RestControllerAdvice(basePackages = "edu.nf.placeorder.web")
@Slf4j
public class GlobalExceptionAdvice {

    @ExceptionHandler(GlobalException.class)
    public ResultVO handleGlobalException(GlobalException e) {
        log.error(e.getMessage(), e);
        return ResultVO.error(e.getErrorCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultVO handleException(Exception e) {
        log.error(e.getMessage(), e);
        return ResultVO.error(500, "服务器异常，请稍后尝试");
    }
}